package io.youngledo.usb.license;

/// 许可证系统测试程序
///
/// 用于测试许可证系统的各项功能。
///
/// ## 测试内容
/// 1. 许可证管理器初始化
/// 2. 功能门控检查
/// 3. 许可证信息显示
public class LicenseSystemTest {

    public static void main(String[] args) {
        System.out.println("========================================");
        System.out.println("🧪 许可证系统测试");
        System.out.println("========================================\n");

        try {
            // 1. 初始化许可证管理器
            System.out.println("1️⃣  初始化许可证管理器...");
            LicenseManager.initialize();
            System.out.println("✅ 初始化完成\n");

            // 2. 显示当前许可证信息
            System.out.println("2️⃣  当前许可证信息：");
            System.out.println("----------------------------------------");
            System.out.println(LicenseManager.getLicenseInfo());
            System.out.println("----------------------------------------\n");

            // 3. 测试功能门控
            System.out.println("3️⃣  功能门控测试：");
            System.out.println("----------------------------------------");

            testFeature(Feature.BATCH_OPERATIONS);
            testFeature(Feature.TASK_MANAGEMENT);
            testFeature(Feature.UNLIMITED_CONNECTIONS);
            testFeature(Feature.ADVANCED_UI);
            testFeature(Feature.ADVANCED_PROGRESS);

            System.out.println("----------------------------------------\n");

            // 4. 测试许可证状态检查
            System.out.println("4️⃣  许可证状态检查：");
            System.out.println("----------------------------------------");
            LicenseManager.checkLicenseStatus();
            System.out.println("✅ 许可证状态正常");
            System.out.println("----------------------------------------\n");

            // 5. 显示许可证文件路径
            System.out.println("5️⃣  许可证文件位置：");
            System.out.println("----------------------------------------");
            System.out.println(LicenseManager.getLicenseFilePath());
            System.out.println("----------------------------------------\n");

            System.out.println("========================================");
            System.out.println("✅ 测试完成！");
            System.out.println("========================================");

        } catch (Exception e) {
            System.err.println("\n❌ 测试失败: " + e.getMessage());
            e.printStackTrace();
        }
    }

    private static void testFeature(Feature feature) {
        var isEnabled = FeatureGate.isEnabled(feature);
        var status = isEnabled ? "✅ 已启用" : "❌ 未启用";
        var reason = isEnabled ? "" : " - " + FeatureGate.getDisabledReason(feature);

        System.out.printf("%-20s %s%s%n",
                feature.getDisplayName(),
                status,
                reason
        );
    }
}
